<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%--
- Author(s): thinkpad
- Date: 2018-03-28 20:40:57
- Description:
    --%>
    <head>
        <title>
            项目列表查询
        </title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <script src="<%= request.getContextPath() %>/common/nui/nui.js" type="text/javascript">
        </script>
    </head>
    <body style="width:98%;height:95%;">
        <div class="nui-panel" title="项目列表查询" iconCls="icon-add" style="width:100%;height:15%;" showToolbar="false" showFooter="true">
            <div id="增加项目" class="nui-form" align="left" style="height:100%">
                <!-- 数据实体的名称 -->
                <input class="nui-hidden" name="criteria/_entity" value="com.zhmy.xmgl.ZHMY_PROJECT.ZhmyProject">
                <!-- 排序字段 -->
                <table id="table1" class="table" style="height:100%">
                    <tr>
                        <td class="form_label">
                            项目名称:
                        </td>
                        <td colspan="1">
                            <input class="nui-textbox" name="criteria/_expr[1]/projectName"/>
                            <input class="nui-hidden" name="criteria/_expr[1]/_op" value="like">
                            <input class="nui-hidden" name="criteria/_expr[1]/_likeRule" value="all">
                        </td>
                        <td class="form_label">
                            项目进度:
                        </td>
                        <td colspan="1">
                            <input class="nui-dictcombobox" dictTypeId="PROJECT_PROGRESS" name="criteria/_expr[2]/projectStatus" />
                            <input class="nui-hidden" name="criteria/_expr[2]/_op" value="=">
                        </td>
                    
                        <td class="form_label">
                            客户名称:
                        </td>
                        <td colspan="3">
                        	<input id="lookup2" name="criteria/_expr[3]/zhmyCustomer.customerId" class="nui-lookup" style="width: 200px;"
							textField="customerCompanyName" valueField="customerId" popupWidth="auto"
							popup="#gridPanel" grid="#datagrid" multiSelect="true" />
                            <input class="nui-hidden" name="criteria/_expr[3]/_op" value="=">
                        </td>
                        <td colspan="3">
                        <a class="nui-button" onclick="search()">
                查询
            </a>
            <a class="nui-button" onclick="reset()">
                重置
            </a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>

        <div class="nui-panel" title="项目列表" iconCls="icon-add" style="width:100%;height:85%;" showToolbar="false" showFooter="false" >
            <div class="nui-toolbar" style="border-bottom:0;padding:0px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="nui-button" iconCls="icon-add" onclick="add()">
                                增加
                            </a>
                            <a id="update" class="nui-button" iconCls="icon-edit" onclick="edit()">
                                编辑
                            </a>
                            <a class="nui-button" iconCls="icon-remove" onclick="remove()">
                                删除
                            </a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="nui-fit">
                <div 	id="datagrid1" 
                		dataField="zhmyprojects" 
                		class="nui-datagrid" 
                		style="width:100%;height:100%;" 
                		url="com.zhmy.xmgl.zhmyprojectbiz.queryZhmyProjects.biz.ext" 
                		pageSize="10" 
                		showPageInfo="true" 
                		multiSelect="true" 
                		onselectionchanged="selectionChanged" 
                		allowSortColumn="false" 
                		ondrawcell="addLink">
                		
                    <div property="columns">
                       <!-- <div type="indexcolumn">
                        </div>-->
                        <div type="checkcolumn">
                        </div>
                        <div field="projectId" headerAlign="center" allowSort="true" visible="false">
                            项目id
                        </div>
                        <div field="projectName" headerAlign="center" allowSort="true" >
                            项目名称
                        </div>
                        <div field="zhmyCustomer.customerName" headerAlign="center" allowSort="true" >
		客户名称
                        </div>
                        <div field="projectStatus" headerAlign="center" allowSort="true" dicttypeid="PROJECT_PROGRESS" renderer="projectProgress">
                            项目进度
                        </div>
                        <div field="projectPactTime" headerAlign="center" allowSort="true" >
                            合约交付时间
                        </div>
                        <div field="projectExpectTime" headerAlign="center" allowSort="true" >
                            预计交付时间
                        </div>
                        <div name="log" headerAlign="center" allowSort="true" >
		日志
                        </div>
                         <div name="operation"  headerAlign="center" width="250px;">
		操作
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
         <!--  look up  start-->
        <div id="gridPanel" class="nui-panel" title="header" iconCls="icon-add" style="width:300px;height:200px;"
		showToolbar="true" showCloseButton="true" showHeader="false" bodyStyle="padding:0"borderStyle="border:0">
			<div property="toolbar" style="padding:5px;padding-left:8px;text-align:center;">
				<div style="float:left;padding-bottom:2px;"> 
					<span>客戶名称:</span>
					<input id="keyText" class="nui-textbox" style="width:160px;"
		onenter="onSearchClick"/>
					<a class="nui-button" onclick="onSearchClick">查询</a>
					<a class="nui-button" onclick="onClearClick">清除</a>
				</div>
				<div style="float:right;padding-bottom:2px;">
					<a class="nui-button" onclick="onCloseClick">关闭</a>
				</div>
				<div style="clear:both;"></div>
			</div>
			<div id="datagrid" class="nui-datagrid" style="width:100%;height:100%;"
		borderStyle="border:0" showPageSize="false" showPageIndex="false" dataField="zhmycustomers" 
		url="<%= request.getContextPath() %>/com.zhmy.xmgl.zhmycustomerbiz.queryZhmyCustomers.biz.ext">
				<div property="columns">
					<div type="checkcolumn"></div>
					<div field="customerCompanyName" width="120" headerAlign="center" allowSort="true">公司名称</div>
					<div field="customerName" width="120" headerAlign="center" allowSort="true">联系人</div>
				</div>
			</div>
		</div>
		<!--  look up  end-->
        
        <script type="text/javascript">
            nui.parse();
            var grid = nui.get("datagrid1");

            // 处理项目进度字典显示
            function projectProgress(e) {
                return nui.getDictText("PROJECT_PROGRESS", e.value);
            }
            
            var formData = new nui.Form("#增加项目").getData(false,false);
            grid.load(formData);

            //新增
            function add() {
                nui.open({
                    url: "<%= request.getContextPath() %>/xmgl/ZhmyProjectForm.jsp",
                    title: "新增记录", width: 600, height: 250,
                    onload: function () {//弹出页面加载完成
                    var iframe = this.getIFrameEl();
                    var data = {pageType:"add"};//传入页面的json数据
                    iframe.contentWindow.setFormData(data);
                    },
                    ondestroy: function (action) {//弹出页面关闭前
                    grid.reload();
                }
                });
            }
            

            //编辑
            function edit() {
                var row = grid.getSelected();
                if (row) {
                    nui.open({
                        url: "<%= request.getContextPath() %>/xmgl/ZhmyProjectForm.jsp",
                        title: "编辑数据",
                        width: 600,
                        height: 450,
                        onload: function () {
                            var iframe = this.getIFrameEl();
                            var data = {pageType:"edit",record:{zhmyproject:row}};
                            //直接从页面获取，不用去后台获取
                            iframe.contentWindow.setFormData(data);
                       	},
                        ondestroy: function (action) {
                            grid.reload();
                        }
                    });
                } else {
                     nui.alert("请选中一条记录","提示");
                }
            }

                    //删除
                    function remove(){
                        var rows = grid.getSelecteds();
                        if(rows.length > 0){
                            nui.confirm("确定删除选中记录？","系统提示",
                            function(action){
                                if(action=="ok"){
                                    var json = nui.encode({zhmyprojects:rows});
                                    grid.loading("正在删除中,请稍等...");
                                    $.ajax({
                                        url:"<%= request.getContextPath() %>/xmgl/com.zhmy.xmgl.zhmyprojectbiz.deleteZhmyProjects.biz.ext",
                                        type:'POST',
                                        data:json,
                                        cache: false,
                                        contentType:'text/json',
                                        success:function(text){
                                            var returnJson = nui.decode(text);
                                            if(returnJson.exception == null){
                                                grid.reload();
                                                nui.alert("删除成功", "系统提示", function(action){
                                                    });
                                                }else{
                                                    grid.unmask();
                                                    nui.alert("删除失败", "系统提示");
                                                }
                                            }
                                    });
                                }
                            });
	                    }else{
	                        nui.alert("请选中一条记录！");
	                    }
	                }

                    //重新刷新页面
                    function refresh(){
                        var form = new  nui.Form("#增加项目");
                        var json = form.getData(false,false);
                        grid.load(json);//grid查询
                        nui.get("update").enable();
                    }

                    //查询
                    function search() {
                        var form = new nui.Form("#增加项目");
                        var json = form.getData(false,false);
                        grid.load(json);//grid查询
                    }

                    //重置查询条件
                    function reset(){
                        var form = new nui.Form("#增加项目");//将普通form转为nui的form
                        form.reset();
                    }

                    //enter键触发查询
                    function onKeyEnter(e) {
                        search();
                    }

                    //当选择列时
                    function selectionChanged(){
                        var rows = grid.getSelecteds();
                        if(rows.length>1){
                            nui.get("update").disable();
                        }else{
                            nui.get("update").enable();
                        }
                    }
                                
                    //操作
                    function addLink(e){
						if(e.column.name == "operation"){
							e.cellHtml = "<a style='color:#1B3F91;padding:10px;text-decoration:underline;' href='<%= request.getContextPath() %>/xmgl/ZhmyProgramManage.jsp?projectId="+e.row.projectId+"'>"+
							"<button>管理项目</button><a style='color:#1B3F91;padding:10px;text-decoration:underline;' href='<%= request.getContextPath() %>/xmgl/ZhmyVersionChangeList.jsp?projectId="+e.row.projectId+"'>"+
							"<button>版本管理</button>";
							
						}else if(e.column.name == "log"){
							if (e.row.type == 1) {
								e.cellHtml = "<a style='color:#1B3F91;text-decoration:underline;' href='<%= request.getContextPath() %>/xmgl/ZhmyLogList.jsp?projectId="+e.row.projectId+"'>"+
							"<button>查看日志</button></a>";
							
							}else{
								e.cellHtml = "<button style='color:#1B3F91;text-decoration:none;' onClick=\'addlog("+e.row.projectId+",\""+e.row.projectName+"\")'>添加日志</button>";
							}
						}
					}
					//添加日志
            		function addlog(projectId,projectName) {
							nui.open({
								url : "<%= request.getContextPath() %>/xmgl/ZhmyLogForm.jsp",
								title : "添加日志",
								width : 600,
								height : 300,
								onload : function() {
									var iframe = this.getIFrameEl();
									var data = {
										pageType : "add",
										record:{
											projectId:projectId,
											projectName:projectName
											
										}
									};
									//直接从页面获取，不用去后台获取
									iframe.contentWindow.setFormData(data);
								},
								ondestroy : function(action) {
									grid.reload();
								}
							});
					}

					
		
								
                    //添加选择域
                    var grid1 = nui.get("datagrid");
					var keyText = nui.get("keyText");
					grid1.load();
					function onSearchClick(e) { 
						grid1.load({
							"criteria/_expr[1]/_likeRule" : "all",
							"criteria/_expr[1]/_op" : "like",
							"criteria/_expr[1]/customerCompanyName" : keyText.value,
							"criteria/_orderby[1]/_property" : "customerId",
							"criteria/_orderby[1]/_sort" : "asc"
						});
					}
					
					//关闭		
					function onCloseClick(e) {
						var lookup2 = nui.get("lookup2");
						lookup2.hidePopup(); 
					}
					
					//清楚
					function onClearClick(e) {
						var lookup2 = nui.get("lookup2"); 
						$("[id^=keyText]").val("");
						lookup2.deselectAll();
					}
					
					//上传文件
					function toUploadFile(projectId) {
						nui.open({
							url: "<%= request.getContextPath() %>/xmgl/uploadfile.jsp?projectId="+projectId,
	                        title: "上传文件",
	                        width: 600,
	                        height: 300,
						});
					}
		</script>
	</body>
</html>
